<%@page contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>


<script type="text/javascript">
	var form_url = $.webapp.root+"/admin/oa/forecast/add.do" ;
	var currentYear = $.date.format(new Date(), "yyyy");
	var tabsContainer, org, position, $person_select_dg ;
	$(function() {
		if($('input[name=id]').val().length > 0) {
			loadData($('input[name=id]').val()) ;
		}  else {
			selectField() ;
		}
		
		$("#sy").combobox({
			valueField: 'label', textField: 'value', value: currentYear,
			data: [
			       { label: '2013', value: '2013' },{ label: '2014', value: '2014' },{ label: '2015', value: '2015' },
			       { label: '2016', value: '2016' },{ label: '2017', value: '2017' },{ label: '2018', value: '2018' },
			       { label: '2019', value: '2019' },{ label: '2020', value: '2020' },{ label: '2021', value: '2021' },
			],
			panelHeight:'auto', editable:false, autoShowPanel: true,
			onSelect: function(record) {
				var id = $('input[name=id]').val() ;
				if(id.length > 0) {
					$.post($.webapp.root+"/admin/oa/forecast/getByYear.do", {id: id, year: record.value}, function(result) {
						$('#basic_month_form').form('load', result);
					}, 'json').error(function() { $.easyui.loaded(); });
				}
			}
		}) ;
		
	});
	
	function loadData(id) {
		selectField() ;
		
		form_url = $.webapp.root+"/admin/oa/forecast/update.do" ;
		$.post($.webapp.root+"/admin/oa/forecast/get.do", {id: id, year: "${year}"}, function(result) {
			if (result.id != undefined) {
				$('#basic_info_form').form('load', result);
			}
		}, 'json').error(function() { $.easyui.loaded(); });
		
	}
	
	function selectField() {
		org = $("#org").combotree({
			url : $.webapp.root+"/static_res/org.tree.json", value: '${USER_SESSION.user.org_id}',
			idFiled:'pid', textFiled:'name', editable: false, required:true, lines:true, autoShowPanel: false,
			onSelect: function(record) {
				$("input[name=projDeptName]").val(record.name) ;
			}
		});
		
		var data = {"dictCode": "XMGL_ZT,XMGL_PJWL,XMGL_SZQR,XMGL_GKFL"} ;
		$.post($.webapp.root+"/admin/system/dict/doNotNeedSession_dictAttrMaps.do", data, function(result) {
			$("#XMGL_ZT").combobox({
				editable: false, required:true,
				valueField: 'text', textField: 'text', panelHeight: 'auto', data: result.XMGL_ZT
			}) ;
			$("#XMGL_PJWL").combobox({
				editable: false, required:true,
				valueField: 'text', textField: 'text', panelHeight: 'auto', data: result.XMGL_PJWL
			}) ;
			$("#XMGL_SZQR").combobox({
				editable: false, required:true,
				valueField: 'text', textField: 'text', panelHeight: 'auto', data: result.XMGL_SZQR
			}) ;
			$("#XMGL_GKFL").combobox({
				editable: false, required:true,
				valueField: 'text', textField: 'text', panelHeight: 'auto', data: result.XMGL_GKFL
			}) ;
		}, 'json');
	}
	
	//提交表单数据
	var submitNow = function($d, $dg, flag) {
		var bform = $.webapp.serializeObject("#basic_info_form") ;
		var mform = $.webapp.serializeObject("#basic_month_form") ;
		
		var o = {} ;
		addAttr(o, bform) ;
		addAttr(o, mform) ;
		
		$.post(form_url, o, function(result) { 
			if (result.status) {
				$dg.datagrid('reload');alertify.success(result.msg);$.easyui.loaded();
				if(flag==undefined||flag==false){$d.dialog("close") ;}
			} else {
				$.easyui.loaded();$.messager.alert("错误", result.msg, "error");
			}
		}, 'json').error(function() { $.easyui.loaded(); });
	};
	
	//验证表单
	var submitForm = function($d, $dg, flag) { 
		if($('#basic_info_form').form('validate')) {
			$.easyui.loading({ msg: "数据提交中，请稍等..." });
			submitNow($d, $dg, flag) ;
		}
	};
	//添加数据
	function addAttr(datas, obj){
		$.each(obj, function(p, v){
			datas[p] = v ;
		}) ;
	}
	
	
</script>
<div class="form_container">
<table class="tableform">
	<tr>
		<th style="text-align:left;">属性说明</th>
	</tr>
	<tr>
		<td>
			<div style="float:left;width:200px;">
				<b>PJ完了</b>
				<br>&nbsp;&nbsp;&nbsp;YES：完了/取消 
				<br>&nbsp;&nbsp;&nbsp;NO：未完
			</div>
			<div style="float:left;">
				<b>受注状态</b>
				<br>&nbsp;&nbsp;&nbsp;■引合の受注確率×起動日時の予定通りにリソース投入の確率。
				<br>&nbsp;&nbsp;&nbsp;---------------
				<br>&nbsp;&nbsp;&nbsp;済み：受注済
				<br>&nbsp;&nbsp;&nbsp;99%：　受注確度が95%～99.99%。
				<br>&nbsp;&nbsp;&nbsp;90%：　受注確度が90%以上。
				<br>&nbsp;&nbsp;&nbsp;80%：　受注確度が70%～89%以上。
				<br>&nbsp;&nbsp;&nbsp;70%：　受注確度が50%～70%。
				<br>&nbsp;&nbsp;&nbsp;50%：　受注確度が30%～50%。
				<br>&nbsp;&nbsp;&nbsp;30%：　受注確度が0%～30%。
			</div>
		</td>
	</tr>
</table>
</div>
	
				<form id="basic_info_form">
					<div class="form_container">
						<input type="hidden" name="id" value="${id}" />
						<input type="hidden" name="personId" value="${USER_SESSION.user.emp_id}" />
						<input type="hidden" name="personName" value="${USER_SESSION.user.emp_name}" />
						<input type="hidden" name="projDeptName" value="${USER_SESSION.user.org_name}" />
						<table class="tableform">
							<tr>
								<th>顧客分類：</th>
								<td><input id="XMGL_GKFL" name="custCategory" type="text" class="easyui-combobox" style="width:219px;height:25px;"/></td>
								<th>顧客名称：</th>
								<td><input name="custName" class="easyui-validatebox" data-options="required:true" type="text" /></td>
							</tr>
							<tr>
								<th>案件名称：</th>
								<td colspan="3"><input name="caseName" class="easyui-validatebox" data-options="required:true" type="text" style="width:597px;" /></td>
							</tr>
							<tr>
								<th>PJ完了：</th>
								<td>
									<input id="XMGL_PJWL" name="projOver" type="text" class="easyui-combobox" style="width:219px;height:25px;"/>
								</td>
								<th>状態：</th>
								<td>
									<input id="XMGL_ZT" name="projStatus" type="text" class="easyui-combobox" style="width:219px;height:25px;"/>
								</td>
							</tr>
							<tr>
								<th>受注確度：</th>
								<td>
									<input id="XMGL_SZQR" name="projDegree" type="text" class="easyui-combobox" style="width:219px;height:25px;"/>
								</td>
								<th>部门：</th>
								<td>
									<input id="org" name="projDeptId" style="width:219px;height:25px;" />
								</td>
							</tr>
							<tr>
								<th>PJ責任者：</th>
								<td>
									<input name="projOwner" class="easyui-validatebox" data-options="required:true" type="text" />
								</td>
								<th>PM/PL：</th>
								<td>
									<input name="pm" class="easyui-validatebox" data-options="required:true" type="text" />
								</td>
							</tr>
						</table>
					</form>
					
					<form id="basic_month_form">
						<table class="tableform" style="margin-top:10px;">
							<tr>
								<th>年份：</th>
								<td colspan="5">
									<input id="sy" name="year" style="width:219px;height:25px;" class="easyui-validatebox" type="text" />
								</td>
							</tr>
							<tr>
								<th colspan="3" style="text-align:center;">ON</th>
								<th colspan="3" style="text-align:center">OFF</th>
							</tr>
							<%for(int i=1; i<=12; i++){ %>
							<tr>
								<th style="text-align:center;width:80px;"><%=i%>月：</th>
								<td>
									<input name="zh_up_m<%=i%>" class="easyui-validatebox" type="text" style="width:40px;" data-options="prompt: '上旬'" />
								</td>
								<td>
									<input name="zh_down_m<%=i%>" class="easyui-validatebox" type="text" style="width:40px;" data-options="prompt: '下旬'" />
								</td>
								
								<th style="text-align:center;width:90px;"><%=i%>月：</th>
								<td>
									<input name="jp_up_m<%=i%>" class="easyui-validatebox" type="text" style="width:40px;" data-options="prompt: '上旬'" />
								</td>
								<td>
									<input name="jp_down_m<%=i%>" class="easyui-validatebox" type="text" style="width:40px;" data-options="prompt: '下旬'" />
								</td>
							</tr>
							<%} %>
						</table>
						
					</div>
				</form>


